import java.util.ArrayList;
import java.util.Scanner;

class Student {
    public String name;
    public int age;
    private String id;

    public Student(String name, int age, String id) {
        this.name = name;
        this.age = age;
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public String getId() {
        return id;
    }
}

class StudentManagementSystem {
    private ArrayList<Student> students;

    public StudentManagementSystem() {
        students = new ArrayList<>();
    }

    public void addStudent(Student student) {
        students.add(student);
        System.out.println("学生信息添加成功！");
    }

    public void deleteStudent(String id) {
        for (int i = 0; i < students.size(); i++) {
            if (students.get(i).getId().equals(id)) {
                students.remove(i);
                System.out.println("学生信息删除成功！");
                return;
            }
        }
        System.out.println("找不到该学生的信息！");
    }

    public void searchStudent(String id) {
        for (Student student : students) {
            if (student.getId().equals(id)) {
                System.out.println("学生信息如下：");
                System.out.println("姓名：" + student.getName());
                System.out.println("年龄：" + student.getAge());
                System.out.println("学号：" + student.getId());
                return;
            }
        }
        System.out.println("找不到该学生的信息！");
    }

    public void updateStudent(String id, String newName, int newAge) {
        for (Student student : students) {
            if (student.getId().equals(id)) {
                student.name = newName;
                student.age = newAge;
                System.out.println("学生信息更新成功！");
                return;
            }
        }
        System.out.println("找不到该学生的信息！");
    }
}

public class StudentManagementSystemMenu {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        StudentManagementSystem system = new StudentManagementSystem();

        while (true) {
            System.out.println("学生管理系统");
            System.out.println("1. 查询学生信息");
            System.out.println("2. 添加学生信息");
            System.out.println("3. 删除学生信息");
            System.out.println("4. 更新学生信息");
            System.out.println("0. 结束程序");
            System.out.print("请输入操作编号：");

            int choice = scanner.nextInt();
            scanner.nextLine(); // 读取换行符

            switch (choice) {
                case 0:
                    System.out.println("程序已结束！");
                    return;
                case 1:
                    System.out.print("请输入学生学号：");
                    String searchId = scanner.nextLine();
                    system.searchStudent(searchId);
                    break;
                case 2:
                    System.out.print("请输入学生姓名：");
                    String name = scanner.nextLine();
                    System.out.print("请输入学生年龄：");
                    int age = scanner.nextInt();
                    scanner.nextLine(); // 读取换行符
                    System.out.print("请输入学生学号：");
                    String id = scanner.nextLine();
                    Student newStudent = new Student(name, age, id);
                    system.addStudent(newStudent);
                    break;
                case 3:
                    System.out.print("请输入学生学号：");
                    String deleteId = scanner.nextLine();
                    system.deleteStudent(deleteId);
                    break;
                case 4:
                    System.out.print("请输入学生学号：");
                    String updateId = scanner.nextLine();
                    System.out.print("请输入学生新姓名：");
                    String newName = scanner.nextLine();
                    System.out.print("请输入学生新年龄：");
                    int newAge = scanner.nextInt();
                    scanner.nextLine(); // 读取换行符
                    system.updateStudent(updateId, newName, newAge);
                    break;
                default:
                    System.out.println("无效的操作编号，请重新输入！");
            }
            System.out.println();
        }
    }
}